<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:p="http://primefaces.org/ui"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/pages/home.xhtml">
	<ui:define name="title">
		<h:outputText value="#{text.titConsignataria}" />
	</ui:define>
	<ui:define name="content">
		<p:fieldset id="fieldSetConsignataria"
			legend="#{text.lgdConsignatariaForm}" toggleable="true"
			binding="#{consignatariaController.fieldSetConsignataria}">
			<h:inputHidden id="consignatariaId"
				value="#{consignatariaController.selectedConsignataria.idConsignataria}" />
			<p:messages id="consignatariaMessages" />
			<p:tabView id="tabViewConsignataria" widgetVar="tabView">

				<p:tab id="tabConsignataria" title="#{text.lblConsignataria}">
					<h:panelGrid id="pnlFields" columns="3">
						<h:outputLabel for="name" value="#{text.lblConsignatariaName}" />
						<p:inputText id="name" required="true" size="50" maxlength="40"
							requiredMessage="#{message.requiredConsignatariaName}"
							value="#{consignatariaController.selectedConsignataria.nomConsignataria}" />
						<p:message for="name" />

						<h:outputLabel for="fantasia"
							value="#{text.lblConsignatariaFantasia}" />
						<p:inputText id="fantasia" size="50" maxlength="20"
							value="#{consignatariaController.selectedConsignataria.nomFantasia}" />
						<p:message for="fantasia" />

						<h:outputLabel for="cnpj" value="#{text.lblConsignatariaCNPJ}" />
						<p:inputMask id="cnpj" size="20" maxlength="14"
							value="#{consignatariaController.selectedConsignataria.numCnpj}"
							required="true"
							requiredMessage="#{message.requiredConsignatariaCNPJ}"
							mask="99999999999999">
							<f:validateLength minimum="14" maximum="14" for="cnpj" />
						</p:inputMask>
						<p:message for="cnpj" showSummary="false" />


						<h:outputLabel for="nameFilePens"
							value="#{text.lblConsignatariaFilePens}" />
						<p:inputText id="nameFilePens" size="50" maxlength="15"
							value="#{consignatariaController.selectedConsignataria.nomArquivoPens}" />
						<p:message for="nameFilePens" />

						<h:outputLabel for="nameFileSiape"
							value="#{text.lblConsignatariaFileSiape}" />
						<p:inputText id="nameFileSiape" size="50" maxlength="15"
							value="#{consignatariaController.selectedConsignataria.nomArquivoSiape}" />
						<p:message for="nameFileSiape" />

					</h:panelGrid>

				</p:tab>
				<p:tab id="tabEndereco" title="#{text.lblEndereco}">
					<h:panelGrid id="pnlEndereco" columns="3">
						<h:outputLabel for="endLogra" value="#{text.lblEnderecoLogra}" />
						<p:inputText id="endLogra" size="65" maxlength="45"
							value="#{consignatariaController.selectedConsignataria.endLogra}" />
						<p:message for="endLogra" />

						<h:outputLabel for="endNumero" value="#{text.lblEnderecoNumero}" />
						<p:inputText id="endNumero" size="10" maxlength="10"
							value="#{consignatariaController.selectedConsignataria.endNumero}" />
						<p:message for="endNumero" />

						<h:outputLabel for="endComplemento"
							value="#{text.lblEnderecoComp}" />
						<p:inputText id="endComplemento" size="40" maxlength="20"
							value="#{consignatariaController.selectedConsignataria.endCompl}" />
						<p:message for="endComplemento" />

						<h:outputLabel for="endBairro" value="#{text.lblEnderecoBairro}" />
						<p:inputText id="endBairro" size="40" maxlength="20"
							value="#{consignatariaController.selectedConsignataria.endBairro}" />
						<p:message for="endBairro" />

						<h:outputLabel for="endCidade" value="#{text.lblEnderecoCidade}" />
						<p:inputText id="endCidade" size="40" maxlength="20"
							value="#{consignatariaController.selectedConsignataria.endCidade}" />
						<p:message for="endCidade" />


						<h:outputLabel for="endUF" value="#{text.lblUF}" />
						<p:selectOneMenu id="endUF"
							value="#{consignatariaController.selectedConsignataria.uf.id}"
							effect="fade" style="width:100px;">
							<f:selectItem itemLabel="#{text.lblUnselectCombo}" itemValue="" />
							<f:selectItems value="#{consignatariaController.ufList}"
								var="estado" itemLabel="#{estado.siglaUf}"
								itemValue="#{estado.idUf}" />
						</p:selectOneMenu>
						<p:message for="endUF" />

						<h:outputLabel for="endCEP" value="#{text.lblEnderecoCEP}" />
						<p:inputMask id="endCEP" size="15" maxlength="8" mask="99999999"
							value="#{consignatariaController.selectedConsignataria.endCep}" />
						<p:message for="endCEP" />
					</h:panelGrid>

				</p:tab>
			</p:tabView>

			<p:separator />

			<p:commandButton id="btnNew" value="#{text.btnNew}"
				icon="ui-icon-document"
				actionListener="#{consignatariaController.newConsignataria}"
				immediate="true" update=":frmContent:fieldSetConsignataria"
				onclick="grdConsignataria.unselectAllRows();clearRadioDataTable();"
				oncomplete="tabView.select(0); " />
			<p:commandButton id="btnSave" value="#{text.btnSave}"
				icon="ui-icon-disk"
				update=":frmContent:fieldSetConsignataria, :frmContent:grdConsignataria"
				actionListener="#{consignatariaController.saveConsignataria}"
				process=":frmContent:fieldSetConsignataria"
				oncomplete="handleComplete(xhr, status, args);" />
			<p:commandButton id="btnDelete" value="#{text.btnDelete}"
				icon="ui-icon-trash" onclick="dialogDelete.show()"
				binding="#{consignatariaController.btnDelete}" disabled="true"
				global="false" />
			<p:confirmDialog id="dlgConfirmDelete" widgetVar="dialogDelete"
				closable="true" severity="info" appendToBody="true"
				header="#{text.dlgConfirm}" message="#{message.confirmDelete}"
				width="400">
				<p:commandButton id="btnConfirmDelete"
					actionListener="#{consignatariaController.deleteConsignataria}"
					value="#{text.btnConfirm}" icon="ui-icon-check"
					oncomplete="dialogDelete.hide(),tabView.select(0)"
					update=":frmContent:fieldSetConsignataria, :frmContent:grdConsignataria" />
				<p:commandButton id="btnDeclineDelete" onclick="dialogDelete.hide()"
					value="#{text.btnCancel}" icon="ui-icon-cancel" global="false" />
			</p:confirmDialog>

		</p:fieldset>

		<p:spacer height="25" />

		<p:dataTable id="grdConsignataria" var="consignataria"
			value="#{consignatariaController.consignatariaDataModel}"
			widgetVar="grdConsignataria" emptyMessage="#{text.grdEmpty}"
			selection="#{consignatariaController.selectedConsignataria}"
			paginator="true" rows="10" rowsPerPageTemplate="10,25,50"
			paginatorTemplate=" {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			 sortBy="#{consignataria.nomConsignataria}">

			<p:ajax event="rowSelect" update=":frmContent:fieldSetConsignataria"
				listener="#{consignatariaController.selectConsignataria}"
				immediate="true" oncomplete="tabView.select(0);" />

			<p:column selectionMode="single" style="width:18px" />
			<p:column id="colConsignatariaName"
				headerText="#{text.lblConsignatariaName}"
				sortBy="#{consignataria.nomConsignataria}">
				<h:outputText value="#{consignataria.nomConsignataria}" />
			</p:column>
			<p:column id="colConsignatariaCNPJ"
				headerText="#{text.lblConsignatariaCNPJ}"
				sortBy="#{consignataria.numCnpj}" style="width:200px;">
				<h:outputText value="#{consignataria.numCnpj}" styleClass="cell-align-center"/>
			</p:column>
		</p:dataTable>

		<script type="text/javascript">
			function handleComplete(xhr, status, args) {
				if (!args.validationFailed) {
					$(PrimeFaces.escapeClientId("frmContent:consignatariaMessages"))
							.remove();
				}
			}
		</script>


	</ui:define>
</ui:composition>
</html>